
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../generated/l10n.dart';
import '../manager/config.dart';
import '../models/acctravel_model_entity.dart';

class DateTravelPage extends StatefulWidget {
  AcctravelModelEntity model;
  DateTravelPage({required this.model});

  @override
  State<DateTravelPage> createState() => DateTravelPageState();
}

class DateTravelPageState extends State<DateTravelPage> {
  DATE_TRAVEL_STATE state = DATE_TRAVEL_STATE.NORMAL;
  PAY_TYPE pay = PAY_TYPE.WECHAT;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar:  AppBar(
        iconTheme: IconThemeData(color: Colors.white),
        centerTitle: true,
        backgroundColor: Colors.transparent,
        shadowColor: Colors.transparent,
        title: Text(S.current.GO_TRAVEL, style: NaviTitleStyle,),
        elevation: 0,
        leading: IconButton(
          icon: Icon(Icons.arrow_back_ios_sharp, color: Colors.black,),
          onPressed: () {
            Navigator.of(context).pop();
          },
        ),
      ),
      body: Container(
        child: Column(
          mainAxisAlignment: state == DATE_TRAVEL_STATE.SUCCESS ? MainAxisAlignment.start : MainAxisAlignment.spaceBetween,
          children: [
            Column(
              children: [
                state == DATE_TRAVEL_STATE.SUCCESS ? successWidget() : Container(),
                Container(
                  height: 114.sp,
                  width: double.infinity,
                  padding: EdgeInsets.only(left: 12.sp, right: 12.sp, top: 12.sp),
                  child: Row(
                    children: [
                      Container(
                        child: ClipRRect(
                          borderRadius: BorderRadius.circular(12.sp),
                          child: Image.network(
                            widget.model.icon,
                            width: 114.sp, height: 114.sp, fit: BoxFit.cover,
                          ),
                        ),
                      ),
                      Container(
                        margin: EdgeInsets.only(left: 12.sp),
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text(widget.model.name, style: TextStyle(
                              color: Color(0xFF110604),
                              fontWeight: FontWeight.bold,
                              fontSize: 16.sp,
                            )),
                            Container(
                              child: Row(
                                children: [
                                  Container( width: 50.sp, height: 18.sp, decoration: BoxDecoration(
                                    color: Color(0xFFFF5147),
                                    borderRadius: BorderRadius.circular(9.sp),
                                  ),
                                    alignment: Alignment.center,
                                    child: Row(
                                      crossAxisAlignment: CrossAxisAlignment.center,
                                      children: [
                                        Container(
                                          child: Image.asset("assets/images/women.png", width: 12.sp, height: 12.sp,),
                                          margin: EdgeInsets.only(left: 5.sp),
                                        ),
                                        Container(
                                          margin: EdgeInsets.only(left: 2.sp),
                                          child: Text(widget.model.age, style: TextStyle(
                                            color: Colors.white,
                                            fontSize: 11.sp,
                                          )),
                                        ),
                                      ],
                                    ),
                                  ),
                                  Container(
                                    margin: EdgeInsets.only(left: 8.sp),
                                    child: Text(widget.model.height + " | " + widget.model.weight, style: TextStyle(
                                      color: Color(0xFF999999),
                                      fontSize: 11.sp,
                                    )),
                                  ),
                                ],
                              ),
                            ),
                            Container(
                              height: 53.sp,
                              width: ScreenUtil().screenWidth - 175.sp,
                              padding: EdgeInsets.only(top: 5.sp),
                              child: Row(
                                children: [
                                  Container(
                                    width: ScreenUtil().screenWidth - 200.sp,
                                    alignment: Alignment.topLeft,
                                    // width: 150.0, // 外部Container的宽度
                                    // padding: EdgeInsets.all(8.0), // 外部Container的内边距
                                    child: Wrap(
                                      spacing: 8.sp,
                                      runSpacing: 8.sp,
                                      children: List.generate(widget.model.scenic.length, (index) {
                                        return Container(
                                          padding: EdgeInsets.only(left: 9.sp, right: 9.sp),
                                          width: 50.sp,
                                          height: 20.sp,
                                          decoration: BoxDecoration(
                                            borderRadius: BorderRadius.circular(10.sp),
                                            border: Border.all(
                                              color: Color(0xFF00CA7E), width: 1.sp,
                                            ),
                                          ),
                                          child: Center(
                                            child: Text(
                                              widget.model.scenic[index],
                                              style: TextStyle(color: Color(0xFF00CA7E), fontSize: 12),
                                            ),
                                          ),
                                        );
                                      }),
                                    ),
                                  )
                                ],
                              ),
                            ),
                          ],
                        ),
                      )
                    ],
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(left: 16.sp, right: 16.sp, top: 20.sp),
                  child: Column(
                    children: [
                      state == DATE_TRAVEL_STATE.SUCCESS ? Container() : Container(
                        alignment: Alignment.topLeft,
                        child: Text(
                          S.current.YOUR_NEEDS,
                          style: TextStyle(color: Color(0xFF333333), fontSize: 15.sp, fontWeight: FontWeight.w700),
                        ),
                      ),
                      insertWidet()
                    ],
                  ),
                )
              ],
            ),
            GestureDetector(
              child: Container(
                width: double.infinity,
                height: 44.sp,
                margin: EdgeInsets.only(left: 16.sp, right: 16.sp, bottom: 30.sp),
                decoration: BoxDecoration(
                  color: Color(0xFF00CA7E),
                  borderRadius: BorderRadius.circular(22.sp),
                ),
                child: Center(
                  child: Text(
                    state == DATE_TRAVEL_STATE.NORMAL ? S.current.SUBMIT_TEXT : (state == DATE_TRAVEL_STATE.PAY ? S.current.ORDER_NOW : S.current.I_KNOW),
                    style: TextStyle(color: Colors.white, fontSize: 16.sp),
                  ),
                ),
              ),
              onTap: () {
                switch (state) {
                  case DATE_TRAVEL_STATE.NORMAL:
                    state = DATE_TRAVEL_STATE.PAY;
                    break;
                  case DATE_TRAVEL_STATE.PAY:
                    state = DATE_TRAVEL_STATE.SUCCESS;
                    break;
                  case DATE_TRAVEL_STATE.SUCCESS:
                    Navigator.of(context).pop();
                    return;
                }

                setState(() {

                });
              },
            ),
          ],
        ),
      ),
    );
  }

  Widget insertWidet() {
    if (state == DATE_TRAVEL_STATE.NORMAL)
      return Container(
        margin: EdgeInsets.only(left: 12.sp, right: 12.sp, top: 28.sp),
        child: TextField(
          style: TextStyle(fontSize: 14.sp),
          maxLines: null,
          keyboardType: TextInputType.multiline,
          decoration: InputDecoration(
              contentPadding: EdgeInsets.symmetric(horizontal: 0.sp, vertical: 0.sp),
              hintText: S.current.INPUT_YOUR_NEEDS,
              border: InputBorder.none, counterText: ""
          ),
          maxLength: 200,
        ),
      );
    else if (state == DATE_TRAVEL_STATE.PAY)
      return Container(
        margin: EdgeInsets.only(left: 12.sp, right: 12.sp, top: 28.sp),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            GestureDetector(
              child: Container(
                child: Row(
                  children: [
                    Image.asset(
                      "assets/images/travel/wechat.png",
                      width: 20.sp,
                      height: 20.sp,
                    ),
                    SizedBox(width: 8.sp,),
                    Text(S.current.WECHAT_PAY, style: TextStyle(
                      color: Color(0xFF161823),
                      fontWeight: FontWeight.w700,
                      fontSize: 13.sp,
                    )),
                    SizedBox(width: 39.sp,),
                    Image.asset(
                      pay == PAY_TYPE.WECHAT ? "assets/images/travel/round_select.png" : "assets/images/travel/round_normal.png",
                      width: 16.sp,
                      height: 16.sp,
                    )
                  ],
                ),
              ),
              onTap: () {
                pay = PAY_TYPE.WECHAT;
                setState(() {

                });
              },
            ),
            GestureDetector(
              child: Container(
                child: Row(
                  children: [
                    Image.asset(
                      "assets/images/travel/alipay.png",
                      width: 20.sp,
                      height: 20.sp,
                    ),
                    SizedBox(width: 8.sp,),
                    Text(S.current.ALI_PAY, style: TextStyle(
                      color: Color(0xFF161823),
                      fontWeight: FontWeight.w700,
                      fontSize: 13.sp,
                    )),
                    SizedBox(width: 39.sp,),
                    Image.asset(
                      pay == PAY_TYPE.ALI ? "assets/images/travel/round_select.png" : "assets/images/travel/round_normal.png",
                      width: 16.sp,
                      height: 16.sp,
                    )
                  ],
                ),
              ),
              onTap: () {
                pay = PAY_TYPE.ALI;
                setState(() {

                });
              },
            )
          ],
        ),
      );
    else
      return Container();
  }
  
  Widget successWidget() {
    return Container(
      height: 220.sp,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.end,
        children: [
          Image.asset("assets/images/travel/success.png", width: 80.sp, height: 80.sp,),
          Container(
            margin: EdgeInsets.only(top: 12.sp, bottom: 18.sp),
            child: Text(S.current.TRAVEL_SUCCESS, style: TextStyle(
              color: Color(0xFF110604),
              fontSize: 20.sp,
              fontWeight: FontWeight.w800
            )),
          ),
        ],
      ),
    );
  }
}